#include "PowerFlowCalculation.h"


gsl_matrix* GradsMatrix(Node m_Node[],gsl_matrix* m_G,gsl_matrix *m_B,int Node_Num,int GenCount)
{
    gsl_matrix *h1=gsl_matrix_alloc(GenCount+Node_Num*2-1,1);

    
    for(int i=0;i<Node_Num;i++){
        for (int j=0;j<Node_Num;j++){
            double f = m_Node[i].Angle - m_Node[j].Angle;
            gsl_matrix_set(h1,i+GenCount,0,gsl_matrix_get(h1,i+GenCount,0)+2*m_Node[j].Vol*gsl_matrix_get(m_G,i,j)*cos(f));

        }
    }
    //PRINT_MATRIX(h1);
    for(int i=0;i<Node_Num-1;i++){
        for(int j=0;j<Node_Num;j++){
            if(i!=j){
                double f=m_Node[i].Angle-m_Node[j].Angle;
                gsl_matrix_set(h1,i+GenCount+Node_Num,0,gsl_matrix_get(h1,i+GenCount+Node_Num,0)-2*m_Node[i].Vol*m_Node[j].Vol*gsl_matrix_get(m_G,i,j)*sin(f));
            }
        }
    }

    return h1;


}